<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>关爱健康</title>
    <meta name="description" content="关爱健康">
    <meta name="keywords" content="关爱健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="../img/favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/axios-0.18.0.js"></script>
    <style type="text/css">
        .el-main {
            position: absolute;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"><img src="../img/logo3.png"></span>
                </a>
                <div class="right-menu">
                    <span class="help">
                        <!--<i class="fa fa-exclamation-circle" aria-hidden="true"></i>-->
                        <el-button type="text"
                                   icon="el-icon-chat-line-round"
                                   style="color: #f0f0f0"
                                   @click="openTheNotification">
                            <font color="#f0f8ff">帮助</font>
                        </el-button>
                    </span>
                    <el-dropdown class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user2-160x160.jpg" class="user-avatar">
                            {{username}}
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <div @click="handlePassword">
                                <el-dropdown-item divided>
                                    <span style="display:block;">修改密码</span>
                                </el-dropdown-item>
                            </div>
                            <a href="/logout.do">
                                <el-dropdown-item divided>
                                    <span style="display:block;">退出</span>
                                </el-dropdown-item>
                            </a>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="(menu,index) in menuList" :index="menu.path" :key="index">
                        <template slot="title">
                            <i class="fa" :class="menu.icon"></i>
                            {{menu.name}}
                        </template>
                        <template v-for="child in menu.children">
                            <el-menu-item :index="child.path">
                                <a :href="child.linkUrl" target="right">{{child.name}}</a>
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <iframe name="right" class="el-main" src="work.html" width="100%" height="91%"
                        frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>

    <!--修改密码弹层-->
    <div class="change-form">
        <el-dialog title="修改密码" :visible.sync="popChange" align="center" width="30%">
            <el-form ref="dataChangeForm" :model="user" :rules="rules" label-position="right"
                     label-width="100px">
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="用户名">
                            <el-input v-model="user.username" disabled/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="原密码" prop="oldPassword">
                            <el-input v-model="user.oldPassword" type="password"></el-input>
                        </el-form-item>
                    </el-col>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="新密码" prop="password">
                            <el-input v-model="user.password" type="password"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="确认密码">
                            <el-input v-model="conPassword" type="password"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="popChange=false">取消</el-button>
                <el-button type="primary" @click="changePassword()">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>
</body>
<script type="text/javascript">
    const vue = new Vue({
        el: '#app',
        data: {
            username: '',//当前登录用户的用户名
            menuList: [],
            /*menuList: [
                {
                    "path": "1",
                    "title": "工作台",
                    "icon": "fa-dashboard",
                    "children": []
                },
                {
                    "path": "2",
                    "title": "会员管理",
                    "icon": "fa-user-md",
                    "children": [
                        {
                            "path": "/2-1",
                            "title": "会员档案",
                            "linkUrl": "member.html",
                            "children": []
                        },
                        {
                            "path": "/2-2",
                            "title": "体检上传",
                            "linkUrl": "member_upload.html",
                            "children": []
                        },
                        {
                            "path": "/2-3",
                            "title": "会员统计",
                            "linkUrl": "all-item-list.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "3",
                    "title": "预约管理",
                    "icon": "fa-tty",
                    "children": [
                        {
                            "path": "/3-1",
                            "title": "预约列表",
                            "linkUrl": "ordersettinglist.html",
                            "children": []
                        },
                        {
                            "path": "/3-2",
                            "title": "预约设置",
                            "linkUrl": "ordersetting.html",
                            "children": []
                        },
                        {
                            "path": "/3-3",
                            "title": "套餐管理",
                            "linkUrl": "setmeal.html",
                            "children": []
                        },
                        {
                            "path": "/3-4",
                            "title": "检查组管理",
                            "linkUrl": "checkgroup.html",
                            "children": []
                        },
                        {
                            "path": "/3-5",
                            "title": "检查项管理",
                            "linkUrl": "checkitem.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "4",
                    "title": "健康评估",
                    "icon": "fa-stethoscope",
                    "children": [
                        {
                            "path": "/4-1",
                            "title": "中医体质辨识",
                            "linkUrl": "all-medical-list.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "5",     //菜单项所对应的路由路径
                    "title": "统计分析",     //菜单项名称
                    "icon": "fa-heartbeat",
                    "children": [//是否有子菜单，若没有，则为[]
                        {
                            "path": "/5-1",
                            "title": "会员数量统计",
                            "linkUrl": "report_member.html",
                            "children": []
                        },
                        {
                            "path": "/5-2",
                            "title": "套餐预约占比统计",
                            "linkUrl": "report_setmeal.html",
                            "children": []
                        },
                        {
                            "path": "/5-3",
                            "title": "运营数据统计",
                            "linkUrl": "report_business.html",
                            "children": []
                        },

                    ]
                },
                {
                    "path": "6",     //菜单项所对应的路由路径
                    "title": "系统设置",     //菜单项名称
                    "icon": "fa-cog",
                    "children": [//是否有子菜单，若没有，则为[]
                        {
                            "path": "/6-1",
                            "title": "菜单管理",
                            "linkUrl": "menu.html",
                            "children": []
                        },
                        {
                            "path": "/6-2",
                            "title": "用户管理",
                            "linkUrl": "user.html",
                            "children": []
                        },
                        {
                            "path": "/6-3",
                            "title": "角色管理",
                            "linkUrl": "role.html",
                            "children": []
                        },
                        {
                            "path": "/6-4",
                            "title": "权限管理",
                            "linkUrl": "permission.html",
                            "children": []
                        },

                    ]
                }
            ],*/
            popChange: false,
            user: {},
            conPassword: null,
            rules: {//校验规则 饿了么ui规定的
                password: [{required: true, message: '新密码为必填项', trigger: 'blur'}],
                oldPassword: [{required: true, message: '原密码为必填项', trigger: 'blur'}]
            }
        },
        //获取用户的权限
        created() {
            //发送ajax请求，请求Controller获取当前登录用户的用户名，展示到页面中
            axios.get("/user/getUsername.do").then((res) => {
                if (res.data.flag) {
                    this.username = res.data.data;
                    this.user.username = res.data.data;//回显到修改密码的用户名编辑框{params: {"username": this.username}}
                    axios.get("/menu/findMenuByUsername.do?username=" + this.username).then((res) => {
                        if (res.data.flag) {
                            this.menuList = res.data.data;
                        } else {
                            this.$message(res.data.message);
                        }
                    })
                }
            });
        },
        methods: {
            //点击修改密码
            handlePassword() {
                this.popChange = true;
                if (this.$refs["dataChangeForm"] !== undefined) {
                    this.$refs["dataChangeForm"].resetFields();
                    this.conPassword = null;
                }
            },
            //修改密码
            changePassword() {
                //先判断校验是否通过
                this.$refs['dataChangeForm'].validate((valid) => {
                    if (valid) {
                        this.$confirm('此操作将修改您的密码, 是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            //判端两次新密码是否相同
                            var password1 = this.user.password;
                            var password2 = this.conPassword;
                            if (password1 == password2) {
                                axios.post("/user/modifyPassword.do", this.user).then((res) => {
                                    this.popChange = false;
                                    if (res.data.flag) {
                                        this.$message.success(res.data.message);
                                        top.location.href = "/logout.do";//修改完密码退登录
                                    } else {
                                        this.$message.error(res.data.message);
                                    }
                                }).catch((res) => {
                                    this.showMessage(res);
                                });
                            } else {
                                this.$message.error("两次密码不一致！");
                            }
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '操作已取消'
                            });
                        });
                    } else {
                        this.$message.error("表单数据校验失败");
                        return false;
                    }
                });
            },
            openTheNotification() {
                const h = this.$createElement;
                this.$notify({
                    title: '关于本项目',
                    message: h('i', {style: 'color: teal'}, '本项目是一款应用与健康管理机构的业务系统，实现健康管理机构工作内容可视化、会员管理专业化、健康评估数字化、健康干预流程化、知识库集成化，从而提高健康管理师的工作效率，加强与会员间的互动，增强管理者对健康管理机构运营情况的了解。'),
                    duration: 200,
                });
            },
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });

    $(window).on('resize', function () {
        //屏幕大小自适应，重置容器高宽
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
